package summary;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: 海琳琦
 * @Date: 2022/7/10 10:08
 * https://leetcode.cn/problems/employee-importance/
 */
public class Title690II {

    class Employee {
        public int id;
        public int importance;
        public List<Integer> subordinates;
    }

    int count;

    public int getImportance(List<Employee> employees, int id) {
        Map<Integer, Employee> hash = new HashMap<>();
        for (Employee e : employees) {
            hash.put(e.id, e);
        }
        dfs(hash, id);
        return count;
    }

    private void dfs(Map<Integer, Employee> hash, int id) {
        Employee employee = hash.get(id);
        count += employee.importance;
        for (Integer peopleId : employee.subordinates) {
            dfs(hash, peopleId);
        }
    }


    public static void main(String[] args) {

    }
}
